package com.guigu.tms.dispatch.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.guigu.tms.commons.dispatch.entity.ScheduleJob;
import com.guigu.tms.dispatch.mapper.ScheduleJobMapper;
import com.guigu.tms.dispatch.service.IScheduleJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ScheduleJobService implements IScheduleJobService {
    @Autowired
    private ScheduleJobMapper scheduleJobMapper;

    @Override
    public boolean add(ScheduleJob schedulerJob) {
        scheduleJobMapper.insert(schedulerJob);
        return true;
    }

    @Override
    public boolean update(ScheduleJob scheduleJob) {
        scheduleJobMapper.updateById(scheduleJob);
        return true;
    }

    @Override
    public boolean updateStatus(String jobId, Integer status) {
        UpdateWrapper<ScheduleJob> wrapper=new UpdateWrapper<>();
        wrapper.eq("id",jobId);
        wrapper.set("status",status);
        scheduleJobMapper.update(null,wrapper);
        return true;
    }

    @Override
    public ScheduleJob getScheduleJob(String jobId) {
        return scheduleJobMapper.selectById(jobId);
    }
}
